#include "Camera.h"

namespace PGE2D
{

	Camera::Camera()
	{
		p_position = D3DXVECTOR3( 0.0f, 0.0f, 10.0f );
		p_updir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );

		float ratio = 640.f / 480.f;
		setPerspective( 3.14159f / 4.f, ratio, 1.f, 2000.f );
	}

	Camera::~Camera() {}

	void Camera::setPerspective( float fov, float aspectRatio, float nearRange, float farRange)
	{
		setFOV(fov);
		setAspectRation(aspectRatio);
		setNearRange(nearRange);
		setFarRange(farRange);
	}

	void Camera::Update()
	{
		D3DXMatrixPerspectiveFovLH( &p_matrixProj, p_fov, p_aspectRatio, p_nearRange, p_farRange );
		g_engine->getDevice()->SetTransform( D3DTS_PROJECTION, &p_matrixProj );

		//set the camera's view matrix
		D3DXMatrixLookAtLH( &p_matrixView, &p_position, &p_target, &p_updir );
		g_engine->getDevice()->SetTransform( D3DTS_VIEW, &p_matrixView );
	}

	void Camera::setPosition( float x, float y, float z )
	{
		p_position.x = x;
		p_position.y = y;
		p_position.z = z;
	}

	void Camera::setPosition( D3DXVECTOR3 position )
	{
		setPosition( position.x, position.y, position.z );
	}
};